﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevelopAssistant.GuiTest
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            InitializeControl();
        }

        private void InitializeControl()
        {
            textEditorControl1.Font = new Font(this.Font.FontFamily,14.0f);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("demo");
            foreach (System.IO.FileInfo fi in di.GetFiles())
            {
                string fileContent = string.Empty;
                string fileFormat = string.Empty;
                using (System.IO.FileStream stream = fi.OpenRead())
                {
                    byte[] buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    fileContent = System.Text.Encoding.UTF8.GetString(buffer);
                    Array.Clear(buffer,0,buffer.Length);
                    buffer = null;
                }
                fileFormat = fi.Extension;
                SetContent(fileContent,fileFormat);
            }
        }

        private void SetContent(string content, string format)
        {
            string HighlightingName = "XML";

            switch (format.ToUpper())
            {
                case ".JS":
                    HighlightingName = "JavaScript";
                    break;
            }

            this.textEditorControl1.Text = content;
            this.textEditorControl1.SetHighlighting(HighlightingName);
            this.textEditorControl1.EnableFolding = true;

            this.textEditorControl1.Invalidate();
        }
    }
}
